home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / applic / ntp / acts.zoo / inilin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-15  |  6.3 KB  |  206 lines

  1. void inilin()
  2. {
  3. /*
  4.         this subroutine initializes the com port defined by
  5.         global cmport (0=com1, 1=com2, ... etc).
  6.         the initialization parameters are set using param
  7.  
  8.         if BIOS is not defined, do not use bios calls but access the
  9.         hardware directly.  this is done by determining the hardware
  10.         address of the comport by looking in low core locations.
  11. */
  12. #include <stdio.h>
  13. #include "nbstime.h"
  14. #ifdef IBMPC
  15. #include <dos.h>
  16. char param;
  17. #endif
  18. extern int cmport; /* which comport to use ? */
  19. extern int hs;     /* which speed to use ?   */
  20. extern int debug;  /* debug is on if = 1 */
  21. #ifdef IBMPC
  22. extern int lpadr;   /* address of line printer -- determined here */
  23. #ifndef BIOS
  24. extern int cmadr;   /* hardware address of comport -- determined here*/
  25. #endif
  26. extern int lpt;     /* pulse line printer? 1=yes, 0= no */
  27. #endif
  28. extern char number[30];   /* which number to dial, first char = mode*/
  29. int j;
  30. #ifdef SUN
  31. #include <sgtty.h>
  32. struct sgttyb blah,*arg;     /* parameters used for ioctl calls */
  33.     arg= &blah;           /* blah is structure */
  34.     if(hs == 1)
  35.        {
  36.         arg->sg_ispeed=B1200;
  37.         arg->sg_ospeed=B1200;
  38.        }
  39.     else
  40.        {
  41.        arg->sg_ispeed=B300;
  42.        arg->sg_ospeed=B300;
  43.        }
  44.     arg->sg_erase='\177';
  45.     arg->sg_kill='\025';
  46.     arg->sg_flags=RAW;
  47.     j=ioctl(cmport,TIOCSETP,arg);
  48.     if(j != 0) printf("\n Watch out! ioctl status=%d",j);
  49. #endif
  50. #ifdef IBMPC
  51. unsigned char stat;
  52. #endif
  53. /*
  54.     operation of the IBMPC version:
  55.  
  56.         if this is the direct access version of the program, then the
  57.         hardware address of the comport must be either specified in the
  58.         configuration file or determined by looking in low memory.  if
  59.         it was specified in the configuration file, then cmport was set
  60.         to -1 there and cmadr was read from line 6.  in that case we
  61.         don't have to do anything here.  if cmadr is positive, then
  62.         the value must be determined here by looking at the table starting
  63.         at address 400 (hex).
  64.         following variables and code are used to look in low memory
  65.         to get the address of the comport requested in the config. file
  66.         if the address in low memory is zero, then exit with an error.
  67.         since the line printer addresses are stored just after the tty
  68.         port addresses, these variables are also used for getting the
  69.         hardware address of lpt1 (see below)
  70.  
  71.     operation of the SUN version:
  72.  
  73.     the port was opened in setcfg and this subroutine sets the
  74.     speed and other parameters based on values in the config.
  75.     file.
  76. */
  77. #ifdef IBMPC
  78. unsigned int ttyseg = 0x40;
  79. unsigned int ttyoff =    0;
  80. int far *cmptr;
  81. #ifndef BIOS
  82. /*
  83.         first get hardware address of requested comport if necessary
  84.         these address are stored starting at 400.  if cmport is -1,
  85.         then the address was already gotten by setcfg from the configuration
  86.         file and we don't have to do that here.
  87. */
  88.         if(cmport >= 0)
  89.         {
  90.         ttyoff=2*cmport;
  91. #if defined(MSC)==0        /* unclear how to do this in MSC */
  92.         cmptr=MK_FP(ttyseg,ttyoff);
  93. #endif
  94.         cmadr=*cmptr;
  95.         if(cmadr == 0)
  96.            {
  97.            printf("\n Port COM%d not present in configuration.",cmport+1
  98. );
  99.            exit();
  100.            }
  101.         }
  102. /*
  103.         disable interrupts, turn on DTR and RTS, then
  104.         set 8 bits, no parity, 1 stop bit, Div. Latch Acc Bits on
  105. */
  106.         param=0;
  107.         outportb(cmadr+intena,param);
  108.         param=3;
  109.         outportb(cmadr+modreg,param);
  110.         param='\x83';
  111.         outportb(cmadr+lcreg,param);
  112. /*
  113.         now set requested speed using two halves of divisor
  114.         from tables in interface manual
  115. */
  116.         if(hs == 1)
  117.            {
  118.            param=96;
  119.            outportb(cmadr+divlsb,param);
  120.            param=0;
  121.            outportb(cmadr+divmsb,param);
  122.            }
  123.         else
  124.            {
  125.            param='\x80';
  126.            outportb(cmadr+divlsb,param);
  127.            param=1;
  128.            outportb(cmadr+divmsb,param);
  129.            }
  130. /*
  131.         now turn off divisor latch access bits
  132. */
  133.         param=3;
  134.         outportb(cmadr+lcreg,param);
  135. /*
  136.         get modem status
  137. */
  138.         stat=inportb(cmadr+msreg);
  139. #endif
  140. #ifdef BIOS
  141. /*
  142.         if we get here then we are going to do the same stuff using
  143.         BIOS calls. the parameters are:
  144.  
  145.         300 baud        no parity       1 stop bit      8 bits
  146.         0 1 0           0 0             0               1 1
  147.  
  148.         1200 baud       no parity       1 stop bit      8 bits
  149.         1 0 0           0 0             0               1 1
  150.  
  151.         9600 baud       no parity       1 stop bit      8 bits
  152.         1 1 1           0 0             0               1 1
  153. */
  154.         if(hs == 1)param='\x83';
  155.         else       param='\x43';
  156.         _AL=param;
  157.         _AH=0;
  158.         _DX=cmport;
  159.         geninterrupt(0x14);
  160.         stat=_AL;           /* return with modem status  */
  161. #endif
  162. /*
  163.         if this is automatic dialing using either manual or pulse mode
  164.         then be sure that the modem is ready to go.  check DSR
  165. */
  166.         if( (number[3] == 't') || (number[3] == 'T') ||
  167.             (number[3] == 'p') || (number[3] == 'P') )
  168.         {
  169.         if( (stat & 0x20) == 0)
  170.            {
  171.            printf("\nWarning!  modem does not ");
  172.            printf("show data set ready (DSR).");
  173.            }
  174.         }
  175. /*
  176.         now set line printer address if lpt is set to pulse it. if
  177.         lpt is zero so that pulsing is disabled, then return now.
  178.         
  179.         get lpt1 address by looking in low core at address 408
  180. */
  181.         if(lpt == 0) return;
  182.         ttyoff=8;
  183. #if defined(MSC)==0        /* unclear how to do this in MSC */
  184.         cmptr=MK_FP(ttyseg,ttyoff);
  185. #endif
  186.         lpadr=*cmptr;
  187.         if(lpadr == 0)
  188.         {
  189.         printf("\n printer-port not installed in system.");
  190.         printf("\n pulsing selection disabled.");
  191.         lpt=0;
  192.         return;
  193.         }
  194.         outportb(lpadr,1);
  195.         for(j=0; j<200; j++);   /*wait a bit*/
  196.         if( (inportb(lpadr) & 0x1f) == 1)
  197.         {
  198.         outportb(lpadr,0);
  199.         return;
  200.         }
  201.         printf("\n printer-port does not respond to pulse.");
  202.         printf("\n pulsing selection will be disabled.");
  203.         lpt=0;
  204. #endif
  205. }
  206.